﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;



using Meqs.Entity;
using Meqs.Logic.Interface;

namespace Meqs.Logic.Implement
{
    public class StuCauseEvalListLogic : CommonLogic<StuCauseEvalList, int>, IStuCauseEvalListLogic
    {
        private ISchoolInfoLogic _schoolLogic;
        public StuCauseEvalListLogic(ISchoolInfoLogic schoolLogic)
        {
            _schoolLogic = schoolLogic;
        }
        #region Implementation of ICommonLogic<StuCauseEvalList, int>

        /// <sammury>
        /// 创建对象
        /// </sammury>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Create(StuCauseEvalList entity)
        {
            return CreateObject(entity);
        }

        /// <sammury>
        /// 更新对象
        /// </sammury>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Update(StuCauseEvalList entity)
        {
            return UpdateObject(entity);
        }

        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="entityId"></param>
        /// <returns></returns>
        public int Delete(int entityId)
        {
            return DeleteObject(entityId);
        }

        /// <summary>
        /// 删除所有对象
        /// </summary>
        /// <returns></returns>
        public int DeleteAll()
        {
            return DeleteAllObject();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entityId"></param>
        /// <returns></returns>
        public StuCauseEvalList FindById(int entityId)
        {
            return FindObjectById(entityId);
        }

        /// <summary>
        /// 检索对象数量
        /// </summary>
        /// <returns></returns>
        public int FindCount()
        {
            return FindObjectByCount();
        }

        /// <sammury>
        /// 检索对象
        /// </sammury>
        public IList<StuCauseEvalList> FindAll()
        {
            return FindAllObject();
        }

        /// <summary>
        /// 检索对象数量
        /// </summary>
        /// <returns></returns>
        public int FindCount(Hashtable table)
        {
            return FindObjectByCount(table);
        }

        /// <sammury>
        /// 检索对象
        /// </sammury>
        public IList<StuCauseEvalList> FindAll(Hashtable table)
        {
            return FindObject(table);
        }

        #endregion

        #region Implementation of IStuCauseEvalListLogic

        /// <summary>
        /// 查询学分评价清单
        /// </summary>
        /// <param name="reportType"></param>
        /// <param name="causeID"></param>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <param name="schoolYear"></param>
        /// <param name="term"></param>
        /// <param name="schoolMark"></param>
        /// <returns></returns>
        public StuCauseEvalList GetEvalList(int reportType, int causeID, int year, int month, int? schoolYear, int? term, string schoolMark)
        {
            try
            {
                if (schoolYear == null || term == null)
                {
                    SchoolInfo school = _schoolLogic.FindBySchoolMark(schoolMark);
                    schoolYear = school.SchoolYear;
                    term = school.SchoolTerm;
                }
                Hashtable ht = new Hashtable();
                ht.Add("SchoolMark", schoolMark);
                ht.Add("CauseID", causeID);
                ht.Add("ReportDate", new DateTime(year, month, 1));
                ht.Add("ReportType", reportType);
                ht.Add("SchoolYear", schoolYear);
                ht.Add("Term", term);
                return FindCustomerByID<StuCauseEvalList>("StuCauseEvalList.GetEvalList", ht);
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        /// <summary>
        /// 插入学分评价记录
        /// </summary>
        /// <param name="moralityEvalList"></param>
        /// <param name="schoolMark"></param>
        /// <returns></returns>
        public int InsertStuCauseEvalEvalList(StuCauseEvalList moralityEvalList, string schoolMark)
        {
            Hashtable ht = new Hashtable();
            ht.Add("StuCauseEvalList", moralityEvalList);
            ht.Add("SchoolMark", schoolMark);
            return (int)InsertCustomer("StuCauseEvalList.InsertStuCauseEvalList", ht);
        }

        #endregion
    }
}